var express = require('express');
var router = express.Router();

router.get('/', function (req, res) {
//先去有没有cookie
    if (req.cookies.islogin) {
        console.log('usecookies-cookies:' + req.cookies.islogin);
        req.session.islogin = req.cookies.islogin;
    }

    if (req.session.islogin) {
        console.log('usesession-cookies:' + req.session.islogin);
        res.locals.islogin = req.session.islogin;
    }

    res.render('usecookies', { title: '使用cookies示例' });
});

router.post('/', function (req, res) {

    req.session.islogin = 'success';
    res.locals.islogin = req.session.islogin;
//设置cookie
    res.cookie('islogin', 'sucess', { maxAge: 60000 });

    res.render('usecookies', { title: '使用cookies示例' });
});

module.exports = router;